﻿using System;

namespace CucumberRunner{
    public class CucumberService{
        private readonly Func<User, IDisposable> impersonatorCreator;
        private readonly IProfileRunner profileRunner;

        public CucumberService() : this((x) => new Impersonator(x.Name, x.Domain, x.Password), new ProfileRunner()){}

        public CucumberService(Func<User, IDisposable> impersonatorCreator, IProfileRunner profileRunner){
            this.impersonatorCreator = impersonatorCreator;
            this.profileRunner = profileRunner;
        }

        public CucumberResults Run(string testdirectory, string batchfilename, string profile, string outputfilename, User user){
            using (impersonatorCreator(user)){
                return profileRunner.Run(testdirectory, batchfilename, profile, outputfilename);
            }
        }

        public CucumberResults Run(string testdirectory, string batchfilename, string profile, string outputfilename){
            return profileRunner.Run(testdirectory, batchfilename, profile, outputfilename);
        }
    }
}